package com.biz.primus.management.promotion.service;

import com.biz.primus.base.vo.promotion.PromotionProductReqVo;
import com.biz.primus.base.vo.promotion.PromotionProductVo;
import com.biz.primus.model.promotion.vo.DiscountRateVo;
import com.biz.primus.model.promotion.vo.JqGridTableViewVo;
import com.biz.primus.model.promotion.vo.PromotionCouponVo;
import com.biz.primus.model.promotion.vo.SpecialOfferProductVo;
import com.google.common.collect.Lists;
import java.math.BigDecimal;
import java.util.List;
import java.util.stream.IntStream;
import org.springframework.stereotype.Service;

/**
 * @author david-liu
 */
@Service
public class PromotionSupportService {

    public JqGridTableViewVo<SpecialOfferProductVo> listPromotionProductsInSpecialOffer(Long specialOfferPromotionId) {
        List<SpecialOfferProductVo> specialOfferProductVos = Lists.newArrayList();
        IntStream.rangeClosed(1, 10).forEach(i -> {
            Integer prefix = i;
            SpecialOfferProductVo productVo = new SpecialOfferProductVo();
            productVo.setProductId((long) prefix);
            productVo.setProductName("名称" + prefix);
            productVo.setBrandName("品牌" + prefix);
            productVo.setCategoryName("分类" + prefix);
            productVo.setProductCode(String.valueOf(prefix));
            productVo.setPurchaseQuantityLimit(5);
            productVo.setPurchaseQuantityLimit(prefix);
            specialOfferProductVos.add(productVo);
        });
        JqGridTableViewVo<SpecialOfferProductVo> jqGridTableViewVo = new JqGridTableViewVo<>();
        jqGridTableViewVo.setPage(1);
        jqGridTableViewVo.setTotal(1);
        jqGridTableViewVo.setRecords(jqGridTableViewVo.getRecords());
        jqGridTableViewVo.setRows(specialOfferProductVos);
        return jqGridTableViewVo;
    }

    public List<PromotionProductVo> searchPromotionProducts(PromotionProductReqVo reqVo) {
        List<PromotionProductVo> ret = Lists.newArrayList();
        IntStream.rangeClosed(1, 5).forEach(i -> {
            Integer p = i;
            PromotionProductVo vo = new PromotionProductVo();
            vo.setProductId(Long.valueOf(p));
            vo.setProductName("商品" + p);
            vo.setProductCode(String.valueOf(p));
            vo.setCategoryName("分类" + p);
            vo.setCategoryId(Long.valueOf(p));
            vo.setBrandId(Long.valueOf(p));
            vo.setBrandName("品牌" + p);
            ret.add(vo);
        });
        return ret;
    }

    public JqGridTableViewVo<PromotionProductVo> listPromotionProductsInUserFirstOrder(Long specialOfferPromotionId) {
        List<PromotionProductVo> promotionProductVos = Lists.newArrayList();
        IntStream.rangeClosed(1, 10).forEach(i -> {
            Integer prefix = i;
            PromotionProductVo productVo = new PromotionProductVo();
            productVo.setProductId((long) prefix);
            productVo.setProductName("名称" + prefix);
            productVo.setBrandName("品牌" + prefix);
            productVo.setCategoryName("分类" + prefix);
            productVo.setProductCode(String.valueOf(prefix));
            promotionProductVos.add(productVo);
        });
        JqGridTableViewVo<PromotionProductVo> jqGridTableViewVo = new JqGridTableViewVo<>();
        jqGridTableViewVo.setPage(1);
        jqGridTableViewVo.setTotal(1);
        jqGridTableViewVo.setRecords(jqGridTableViewVo.getRecords());
        jqGridTableViewVo.setRows(promotionProductVos);
        return jqGridTableViewVo;
    }

    public List<PromotionCouponVo> listGiftCouponsInPurchaseGiftPromotion(Long purchaseGiftPromotionId) {
        List<PromotionCouponVo> ret = Lists.newArrayList();
        IntStream.rangeClosed(1, 5).forEach(i -> {
            PromotionCouponVo couponVo = new PromotionCouponVo();
            couponVo.setId((long) i);
            couponVo.setName("优惠券" + i);
            couponVo.setQuantity(i);
            ret.add(couponVo);
        });
        return ret;
    }

    public List<PromotionCouponVo> listGiftCouponsInLuckyOrderPromotion(Long luckyOrderPromotionId) {
        List<PromotionCouponVo> ret = Lists.newArrayList();
        IntStream.rangeClosed(1, 5).forEach(i -> {
            PromotionCouponVo couponVo = new PromotionCouponVo();
            couponVo.setId((long) i);
            couponVo.setName("优惠券" + i);
            couponVo.setQuantity(i);
            ret.add(couponVo);
        });
        return ret;
    }

    public List<PromotionCouponVo> listAllGiftCoupons() {
        List<PromotionCouponVo> ret = Lists.newArrayList();
        IntStream.rangeClosed(1, 10).forEach(i -> {
            PromotionCouponVo couponVo = new PromotionCouponVo();
            couponVo.setId((long) i);
            couponVo.setName("优惠券" + i);
            couponVo.setQuantity(i);
            ret.add(couponVo);
        });
        return ret;
    }

    public List<DiscountRateVo> listDiscountRates(Long discountPromotionId) {
        List<DiscountRateVo> ret = Lists.newArrayList();
        IntStream.rangeClosed(1, 5).forEach(i -> {
            DiscountRateVo rateVo = new DiscountRateVo();
            rateVo.setRateCondition(i);
            rateVo.setDiscountRate(new BigDecimal(Math.random()));
            ret.add(rateVo);
        });
        return ret;
    }
}
